﻿using System.Diagnostics;
using LFSRecord2.Misc;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionMoveKeyFrame : UserActionBase
    {
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public int UniqueID { get; set; }
        public int FrameOffset { get; set; }

        public UserActionMoveKeyFrame()
        {
            Action = UserActionTypes.MoveKeyFrame;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a MoveKeyFrame action");
            foreach (CustomKeyFrame kf in LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames)
            {
                if (kf.UniqueID == UniqueID)
                {
                    kf.FrameNum -= FrameOffset;
                    break;
                }
            }
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a MoveKeyFrame action");
            foreach (CustomKeyFrame kf in LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames)
            {
                if (kf.UniqueID == UniqueID)
                {
                    kf.FrameNum += FrameOffset;
                    break;
                }
            }
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }
    }
}
